<?php
/*入口文件*/

define('CURRENT_TIMESTAMP', time());//定义当前时间
define('DS', DIRECTORY_SEPARATOR);//定义目录分隔符

class SeeboPHP
{
	private $_group_list = array();//组列表
	private $_curr_group = '';//当前组
    public function __construct()
    {
    	
    }
    
    private function __clone()
    {
    	
    }
    
    //程序开始运行，系统开始初始化，加载系统参数，加载路由，加载函数库，根据系统参数初始化
    public function run()
    {
    	//$GLOBALS['start_time'] = microtime(true);//开始运行时间
    	$this->init();
    	$this->loadConfig();
    	$this->loadFunctionLib(); 
    	$this->loadRouter();   	
    	$this->initFromConfig();
    }
    
    //系统初始化
    private function init()
    {
    	set_magic_quotes_runtime(false); //关闭魔术引号
    }
    
    //加载系统参数
    private function loadConfig()
    {
        require_once 'core'. DS .'config.php';
        $GLOBALS['config'] = Config::getInstance();
        $default_config = require_once('core' . DS . 'default_config.php');
        $config = $default_config;
        if (is_file(APPLICATION_PATH . 'config' . DS . 'config.php'))
        {
          $app_config = require_once APPLICATION_PATH . 'config' . DS . 'config.php';
          $config = array_merge($default_config, $app_config);
        }  
        //是否分组了
        if ($config['is_group'] == true)
        {
            $group_list = explode(',', $config['group_list']);
            foreach ($group_list as $value)
            {
                $value = strtolower(trim($value));
                if ($this->_curr_group == $value)
                {
                	
                    $config_file = APPLICATION_PATH. 'config' . DS . $value . DS . 'config.php';
                    if(is_file($config_file))
                    {                   
                        $group_config  = require_once($config_file);
                        $config = array_merge($config, $group_config);
                    }
                }
            }
        }
        foreach ($config as $key=>$value)
        {
        	$key = strtolower($key);
        	$GLOBALS['config']->$key = $value;
        }
        
        
    }
    
    //加载路由
    private function loadRouter()
    {
    	require_once('core/router.php');
    	$router = Router::getInstance();
    	echo $router->action;
    }
    
    //加载函数库
    private function loadFunctionLib()
    {
    	require_once('core/system_function.php');
    } 
    
    //根据系统参数初始化
    private function initFromConfig()
    {
    	date_default_timezone_set(C('default_timezone'));//默认时区
    }
    
    //返回版本号
    public function version()
    {
    	return '0.1';
    }
    
}


